package com.eatme.core.set;

import com.eatme.core.tree.bst.BST;
import com.eatme.core.map.BSTMap;

import java.util.ArrayList;
import java.util.Random;

// 有序集合
public class BSTSet <E extends Comparable<E>> implements Set<E> {

    private BST<E> bst;

    public BSTSet() {
        bst = new BST<>();
    }

    @Override
    public void add(E e) {
        bst.add(e);
    }

    @Override
    public void remove(E e) {
        bst.remove(e);
    }

    @Override
    public boolean contains(E e) {
        return bst.contains(e);
    }

    @Override
    public int getSize() {
        return bst.size();
    }

    @Override
    public boolean isEmpty() {
        return bst.isEmpty();
    }


    public static void main(String[] args) {
        int n = 100;
        for (int j = 0; j < 1000; j++) {
            ArrayList<Integer> arrayList = new ArrayList<>();
            Random random = new Random();
            for (int i = 0; i < 1000; i++) {
                arrayList.add(random.nextInt(1000));
            }
            System.out.println("arraylist size:"+arrayList.size());
            BSTMap<Integer,Integer> map = new BSTMap<>();
            for (int i = 0; i < arrayList.size(); i++) {
                if (map.contains(arrayList.get(i)))
                    map.set(arrayList.get(i),map.get(arrayList.get(i))+1);
                else
                    map.add(arrayList.get(i),1);

            }

            System.out.println("Total different numbers: " +map.getSize());
            System.out.println("Frequency of 1: " +map.get(1));
        }
    }
}
